package com.neusoft.mapper;

import com.neusoft.po.Credit;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CreditMapper {
    @Insert("insert into credit values (null,#{userId},#{type},#{num},#{changeTime},#{expire_time},#{status})")
    public Integer updateCredit(Credit credit);

    @Select("select * from credit where userId=#{userId} and status=1 and expire_time>=#{currentDate} order by expire_time")
    public List<Credit> getCreditByUserId(@Param("userId") String userId,@Param("currentDate") String currentDate);

    @Select("select coalesce(SUM(num),0) from credit where userId=#{userId} and status=1 and expire_time>=#{currentDate}")
    public Integer getTotalCreditByUserId(@Param("userId") String userId,@Param("currentDate") String currentDate);

    @Select("SELECT * FROM credit WHERE userId = #{userId} AND status = 0 AND expire_time < #{currentDate}")
    List<Credit> getExpiredPoints(@Param("userId") String userId, @Param("currentDate") String currentDate);

    @Delete("delete from credit where recordId=#{recordId}")
    Integer deleteCreditByRecordId(@Param("recordId") Integer recordId);

    @Update("UPDATE credit SET status = 0 WHERE status=1 and credit.expire_time < #{currentDate}")
    public int updateExpiredPoints(@Param("currentDate") String currentDate);
}
